package com.bsh.controller.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.bsh.mybatis.model.Account;
import com.bsh.mybatis.model.User;
import com.bsh.service.AccountService;
import com.bsh.service.UserService;
import com.bsh.utils.system.AccountLock;

/**
 * @author gsh
 * @since 0.0.1
 * 
 */
@Controller
public class LockTestController {
	private static Logger log = LoggerFactory.getLogger(LockTestController.class);
	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	HttpSession session;
    @Autowired
    UserService servU;
    @Autowired
    AccountService servAcc;

	/**
	 * 管理员列表
	 */
	@RequestMapping(value = "/api/lock")
	public ModelAndView adminList(@RequestParam(required=false,value="userName") String userName) {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("../test/lockStatus");
		mv.addObject("userName", userName);
		
		if(!StringUtils.isEmpty(userName)){
			User user=servU.getUserByName(userName);
			if(user==null){
				mv.addObject("msg_user", "没有找到用户");
				return mv;
			}
			Account acc = servAcc.getAccountByUserId(user.getId());
			if(acc==null){
				mv.addObject("msg_acc", "没有找到账户");
				return mv;
			}
			boolean status = AccountLock.getLockStatus(acc.getId(),user.getId());
			mv.addObject("status", status);
		}
		
		return mv;
	}
}
